home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src_ansi / ace / c / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-05  |  6.1 KB  |  270 lines

  1. /* << ACE >>
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** Parser: main module **
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.    Date: 26th October-30th November, 1st-13th December 1991,
  24.    14th,20th-27th January 1992, 
  25.    2nd-17th, 21st-29th February 1992, 
  26.    1st,13th,14th,22nd,23rd March 1992,
  27.    21st,22nd April 1992,
  28.    2nd,3rd,11th,15th,16th May 1992,
  29.    7th,8th,9th,11th,13th,14th,28th,29th,30th June 1992,
  30.    2nd-8th,14th-19th,26th-29th July 1992,
  31.    1st-3rd,7th,8th,9th August 1992,
  32.    6th,7th,21st,22nd December 1992,
  33.    13th,30th January 1993,
  34.    2nd,6th,11th,14th,15th,28th February 1993,
  35.    7th,24th March 1993,
  36.    6th,13th,14th,30th June 1993,
  37.    1st,10th July 1993,
  38.    5th,26th September 1993,
  39.    25th October 1993,
  40.    15th-18th November 1993,
  41.    26th,27th December 1993,
  42.    2nd,5th,7th,9th,13th,14th January 1994,
  43.    7th,26th,27th February 1994,
  44.    4th,13th,30th April 1994,
  45.    14th May 1994,
  46.    12th,14th,21st,22nd,25th June 1994,
  47.    10th,14th,24th July 1994,
  48.    14th,19th August 1994,
  49.    11th,12th September 1994,
  50.    5th,11th March 1995,
  51.    8th August 1995,
  52.    6th October 1995,
  53.    10th March 1996
  54.  */
  55.  
  56. #include "acedef.h"
  57. #include <string.h>
  58. #include <stdlib.h>
  59. #include <clib/exec_protos.h>
  60.  
  61. /* externals */
  62. extern char *srcfile, *destfile;
  63. extern int sym;
  64. extern int typ;
  65. extern int lev;
  66. extern int errors;
  67. extern char id[MAXIDSIZE];
  68. extern SYM *curr_item;
  69. extern CODE *curr_code;
  70. extern BOOL end_of_source;
  71. extern FILE *dest;
  72. extern int addr[2];
  73. extern char exit_sub_name[80];
  74. extern BOOL early_exit;
  75. extern int exitvalue;
  76. extern char *rword[];
  77. extern BOOL break_opt;
  78. extern BOOL optimise_opt;
  79. extern BOOL make_icon;
  80. extern BOOL error_log;
  81. extern BOOL asm_comments;
  82. extern BOOL list_source;
  83. extern BOOL wdw_close_opt;
  84. extern BOOL module_opt;
  85. extern BOOL cli_args;
  86. extern BOOL mathffpused;
  87. extern BOOL mathtransused;
  88. extern BOOL dosused;
  89. extern BOOL gfxused;
  90. extern BOOL intuitionused;
  91. extern BOOL translateused;
  92. extern BOOL narratorused;
  93. extern BOOL ontimerused;
  94. extern BOOL iffused;
  95. extern BOOL basdatapresent;
  96. extern BOOL readpresent;
  97.  
  98. /* external functions */
  99. char *version (void);
  100.  
  101. /* functions */
  102. void parse (void)
  103. {
  104.   lev = ZERO;
  105.   addr[lev] = 0;
  106.   new_symtab ();
  107.   create_lists ();
  108.  
  109.   insymbol ();
  110.   block ();
  111.  
  112.   undef_label_check ();
  113.   kill_symtab ();
  114. }
  115.  
  116.  
  117. void show_title (void)
  118. {
  119.   printf ("ACE Amiga BASIC Compiler version %s, copyright ", version ());
  120.   putchar (169);        /* copyright symbol */
  121.   puts (" 1991-1996 David Benn.");
  122. }
  123.  
  124. void usage (void)
  125. {
  126.   printf ("usage: ACE [words | -bcEilmOw] <sourcefile>[.b[as]]\n");
  127.   printf (" ACE -b check for CTRL-C by user\n");
  128.   printf (" ACE -c include each line as a comment\n");
  129.   printf (" ACE -E create the ace.err file in current directory\n");
  130.   printf (" ACE -i create an icon for the executable\n");
  131.   printf (" ACE -l show each line as it's compiled\n");
  132.   printf (" ACE -m create a linkable module\n");
  133.   printf (" ACE -O optimize the assembly source code\n");
  134.   printf (" ACE -w check for window close gadgets\n");
  135. }
  136.  
  137. BOOL check_options (char *opt)
  138. {
  139.   BOOL legalopt = TRUE;
  140.  
  141.   if (*opt != '-')
  142.     return (FALSE);
  143.   /* extract the options */
  144.   opt++;
  145.   if (*opt == '\0')
  146.     legalopt = FALSE;
  147.   else
  148.     while ((*opt != '\0') && (legalopt))
  149.       {
  150.     if (*opt == 'b')
  151.       break_opt = TRUE;
  152.     else if (*opt == 'O')
  153.       optimise_opt = TRUE;
  154.     else if (*opt == 'i')
  155.       make_icon = TRUE;
  156.     else if (*opt == 'E')
  157.       error_log = TRUE;
  158.     else if (*opt == 'c')
  159.       asm_comments = TRUE;
  160.     else if (*opt == 'l')
  161.       list_source = TRUE;
  162.     else if (*opt == 'm')
  163.       module_opt = TRUE;
  164.     else if (*opt == 'w')
  165.       wdw_close_opt = TRUE;
  166.     else
  167.       legalopt = FALSE;
  168.     opt++;
  169.       }
  170.  
  171.   return (legalopt);
  172. }
  173.  
  174. void ctrl_c_break_test (void)
  175. {
  176.   if (SetSignal (0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
  177.     {
  178.       puts ("\n*** Break: ACE terminating.");
  179.       exit (5);
  180.     }
  181. }
  182.  
  183. void dump_reserved_words (void)
  184. {
  185.   int i;
  186.  
  187.   printf ("\nAmigaBASIC RESERVED WORDS: %ld\n\n", (xorsym - abssym) + 1);
  188.  
  189.   for (i = abssym; i <= xorsym; i++)
  190.     {
  191.       printf ("%s\n", rword[i]);
  192.       ctrl_c_break_test ();
  193.     }
  194.  
  195.   printf ("\nACE-SPECIFIC RESERVED WORDS: %ld\n\n", (ycorsym - addresssym) + 1);
  196.  
  197.   for (i = addresssym; i <= ycorsym; i++)
  198.     {
  199.       printf ("%s\n", rword[i]);
  200.       ctrl_c_break_test ();
  201.     }
  202. }
  203.  
  204. int main(int argc, char *argv[])
  205. {
  206.   char *tmparg;
  207.  
  208.   show_title ();
  209.  
  210.   /* 
  211.      ** - get args and compiler switches.
  212.      ** - open source and destination files. 
  213.    */
  214.   if ((argc == 1) || (argc > 3))
  215.     {
  216.       usage ();
  217.       exit (10);
  218.     }                /* arg count mismatch */
  219.  
  220.   /* send reserved words to stdout then quit? */
  221.   tmparg = (char *) malloc (strlen (argv[1]) + 1);
  222.   if (tmparg == NULL)
  223.     {
  224.       puts ("Unable to allocate temporary argument buffer!");
  225.       exit (10);
  226.     }
  227.   else
  228.     {
  229.       strcpy (tmparg, argv[1]);
  230.  
  231.       if (strcmp (strupr (tmparg), "WORDS") == 0)
  232.     {
  233.       dump_reserved_words ();
  234.       if (tmparg)
  235.         free (tmparg);
  236.       exit (0);
  237.     }
  238.       else if (tmparg)
  239.     free (tmparg);
  240.     }
  241.  
  242.   open_shared_libs ();
  243.  
  244.   /* 
  245.      ** compile program 
  246.    */
  247.   if (argc == 2)
  248.     {
  249.       /* source file, no options */
  250.       open_files (argv[1]);
  251.       setup ();
  252.       compile (srcfile, destfile);
  253.     }
  254.   else
  255.     {
  256.       /* options plus source file */
  257.       if (!check_options (argv[1]))
  258.     {
  259.       usage ();
  260.       close_shared_libs ();
  261.       exit (10);
  262.     }            /* illegal options */
  263.       open_files (argv[2]);
  264.       setup ();
  265.       compile (srcfile, destfile);
  266.     }
  267.  
  268.   cleanup ();
  269. }
  270.